import mmlib.mmboom_component_generator as mmboom_component_generator
import mmlib.mmboom_special_transfer as mmboom_special_transfer

class Password :

    def __init__(self):
        self._pwds = []

    def get_pwds(self) :
        return self._pwds

    def set_pwds(self, pwds) :
        self._pwds = pwds

    def add_component(self, elems) :
        if len(self._pwds) == 0 :
            self._pwds = elems
        else :
            new_pwds = []
            for pwd in self._pwds :
                for elem in elems :
                    new_pwds.append(pwd + elem)
            self._pwds = new_pwds

    def filter_min_len(self, length) :
        new_pwds = []
        for pwd in self._pwds :
            if not len(pwd) < length :
                new_pwds.append(pwd)
        self._pwds = new_pwds

    def filter_max_len(self, length) :
        new_pwds = []
        for pwd in self._pwds :
            if not len(pwd) > length :
                new_pwds.append(pwd)
        self._pwds = new_pwds

    # 0->o,O
    def transfer_0(self) :
        self._pwds = mmboom_special_transfer.recur_transfer('0', 0, self._pwds)

    # 1->i,l,a
    def transfer_1(self) :
        self._pwds = mmboom_special_transfer.recur_transfer('1', 0, self._pwds)

    # 2->s,z
    def transfer_2(self) :
        self._pwds = mmboom_special_transfer.recur_transfer('2', 0, self._pwds)

    # s->2,$
    def transfer_s(self) :
        self._pwds = mmboom_special_transfer.recur_transfer('s', 1, self._pwds)

def get_xing(name) :
    return mmboom_component_generator.get_names(name, tname=1)

def get_Xing(name) :
    return mmboom_component_generator.get_names(name, tname=1, ttype=0)

def get_ming(name) :
    return mmboom_component_generator.get_names(name, tname=2)

def get_Ming(name) :
    return mmboom_component_generator.get_names(name, tname=2, ttype=0)

def get_MING(name) :
    return mmboom_component_generator.get_names(name, tname=2, ttype=1)

def get_name(name) :
    return mmboom_component_generator.get_names(name, tname=0)

def get_Name(name) :
    return mmboom_component_generator.get_names(name, tname=0, ttype=0)

def get_NAME(name) :
    return mmboom_component_generator.get_names(name, tname=0, ttype=1)

def get_birh_yyyymmdd(birth) :
    return mmboom_component_generator.get_births(birth, tbirth=0)

def get_birh_yymmdd(birth) :
    return mmboom_component_generator.get_births(birth, tbirth=1)

def get_birh_mmdd(birth) :
    return mmboom_component_generator.get_births(birth, tbirth=2)

def get_birh_yyyy(birth) :
    return mmboom_component_generator.get_births(birth, tbirth=3)

def get_birh_yyyymmdd_with_connector(birth, connector) :
    return mmboom_component_generator.get_births(birth, tbirth=0, connector=connector)

def get_birh_yymmdd_with_connector(birth, connector) :
    return mmboom_component_generator.get_births(birth, tbirth=1, connector=connector)

def get_birh_mmdd_with_connector(birth, connector) :
    return mmboom_component_generator.get_births(birth, tbirth=2, connector=connector)

def get_card(card) :
    return mmboom_component_generator.get_cards(card)

def get_phone(phone) :
    return mmboom_component_generator.get_phones(phone)

if __name__ == "__main__" :

    # information

    name = "张三丰"
    card = "301274199702063719"
    birth = "19970207"
    phone = "13790102265"

    # extract information

    xings = []
    mings = []
    names = []
    births =[]
    cards = []

    xings = get_xing(name)
    print("xing: ", xings)

    xings = get_Xing(name)
    print("Xing: ", xings)

    mings = get_ming(name)
    print("ming: ", mings)

    mings = get_Ming(name)
    print("Ming: ", mings)

    mings = get_MING(name)
    print("MING: ", mings)

    names = get_name(name)
    print("name: ", names)

    names = get_Name(name)
    print("Name: ", names)

    names = get_NAME(name)
    print("NAME: ", names)

    births = get_birh_yyyymmdd(birth)
    print("birh_yyyymmdd: ", births)

    births = get_birh_yymmdd(birth)
    print("birh_yymmdd: ", births)

    births = get_birh_mmdd(birth)
    print("birh_mmdd: ", births)

    births = get_birh_yyyy(birth)
    print("birh_yyyy: ", births)

    births = get_birh_yyyymmdd_with_connector(birth, '.')
    print("birh_yyyymmdd_with_connector: ", births)

    births = get_birh_yymmdd_with_connector(birth, '-')
    print("birh_yymmdd_with_connector: ", births)

    births = get_birh_mmdd_with_connector(birth, '.')
    print("birh_mmdd_with_connector: ", births)

    cards = get_card(card)
    print("card: ", cards)

    phones = get_phone(phone)
    print("phone: ", phones)

    # generator example

    pwds = Password()

    prefixs = ['pku', 'whu', 'zju']

    pwds.add_component(prefixs)

    xings = get_Xing(name)

    pwds.add_component(xings)

    connectors = ['.', ',', '@']

    pwds.add_component(connectors)

    births = get_birh_mmdd(birth)

    pwds.add_component(births)

    mings = get_ming(name)

    pwds.add_component(mings)

    print(pwds.get_pwds())

    pwds.filter_min_len(8)

    pwds.filter_max_len(12)

    print(pwds.get_pwds())

    pwds.transfer_0()

    print(pwds.get_pwds())

    pwds.transfer_s()

    print(pwds.get_pwds())
